class MyIterator {
    constructor(arr, step = 1) {
        this.arr = arr;
        this.index = 0;
        this.isPaused = false;  // 用来控制暂停状态
        this.step = step
    }
    next() {
        if (this.isPaused) {
            return { value: undefined, done: false };
        }
        if (this.index < this.arr.length) {
            const value = this.arr[this.index]
            this.index += this.step
            return { value, done: false };
        } else {
            return { value: undefined, done: true };
        }
    }
    // 暂停迭代
    pause () {
        this.isPaused = true
    }
    // 恢复迭代
    resume() {
        this.isPaused = false
    }

    // 重置迭代器
    reset() {
        this.index = 0
    }
    setStep(step = 1) {
        this.step = step
        console.log(this.index)
    }
    [Symbol.iterator]() {
        return this
    }
}
// 创建迭代器实例
const iterator = new MyIterator([10, 20, 30, 40, 50,60,70], 2);
// 使用 for...of 循环进行迭代
console.log("开始迭代：");
for (const value of iterator) {
    console.log(value);
    if (value === 30) {
        iterator.pause();  // 当值为20时，暂停迭代
        console.log("迭代暂停");
        break;
    }
}
console.log("恢复迭代：");
iterator.setStep(1)
iterator.resume();
for (const value of iterator) {
    console.log(value);  // 继续从20开始迭代
}